<?php
namespace app\common\model;

use think\Model;

class ProductSpell extends Model
{
    /**
     * 根据id 判断实体是否存在，存在则返回实体，否则返回null
     * @param $spell_id
     * @return array|bool|null|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     *
        Select
        om_product_spell.id,
        om_product_spell.cover_img,
        om_product_spell.spell_name,
        om_product_spell.batch_num,
        om_product_spell.spell_price,
        om_product_spell.sales_num,
        om_product.product_price_one,
        FROM_UNIXTIME(om_product_spell.start_time) as start_time,
        FROM_UNIXTIME(om_product_spell.end_time) as end_time,
        om_product.sku_remark,
        om_product.description,
        om_product.img_path
        from om_product_spell
        inner join om_product on om_product_spell.product_id = om_product.id
        where om_product_spell.is_show = 1 and om_product.is_publish = 2
     */
    public function isExistsById($spell_id){
        $field = 'om_product_spell.id,om_product_spell.cover_img,om_product_spell.spell_name,om_product_spell.spell_num,om_product_spell.batch_num,
            om_product_spell.spell_price,om_product_spell.sales_num,om_product.product_price_one,
            FROM_UNIXTIME(om_product_spell.start_time) as start_time, FROM_UNIXTIME(om_product_spell.end_time) as end_time,
            om_product.sku_remark,om_product.description,om_product.img_path,om_product_spell.product_id';
        $where["om_product_spell.id"] = $spell_id;
        $where["om_product_spell.is_show"] = 1;
        $where["om_product.is_publish"] = 2;
        $productSpellmodel = $this->field($field)
            ->join("om_product","om_product_spell.product_id = om_product.id")
            ->where($where)->find();
        return $productSpellmodel;
    }
}